package com.fgw.controller.backend;

import com.fgw.common.Const;
import com.fgw.common.ResponseCode;
import com.fgw.common.ServerResponse;
import com.fgw.pojo.Teacher;
import com.fgw.pojo.Worktrend;
import com.fgw.service.IWorktrendService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.io.Serializable;

/**
 * Created by lyj on 2017/9/15.
 */
@Controller
@RequestMapping("/admin/Worktrend/")
public class WorktrendAdminController {

    @Autowired
    private IWorktrendService iWorktrendService;

    /**
     * 后台分页显示工作动态列表Controller
     * @param session
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "list.do")
    @ResponseBody
    public ServerResponse getNeddWorktrendList(HttpSession session, @RequestParam(value = "pageNum",defaultValue = "1") int pageNum,@RequestParam(value = "pageSize",defaultValue = "5")int pageSize){

        Teacher teacher= (Teacher) session.getAttribute(Const.CURRENT_USER);
        if (teacher==null){
            return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"用户未登录请先登录");
        }else {

            return iWorktrendService.getNeedWorktrendList(pageNum,pageSize);
        }
    }

    /**
     * 后台搜索分页显示工作动态
     * @param session
     * @param title
     * @param soureCrmpy
     * @param wtId
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "search.do",method = RequestMethod.POST)
    @ResponseBody
    public  ServerResponse worktrendSearch(HttpSession session, String title,String soureCrmpy,Integer wtId,
     @RequestParam(value = "pageNum",defaultValue = "1")int pageNum,@RequestParam(value = "pageSize",defaultValue = "5")int pageSize){

        Teacher teacher= (Teacher) session.getAttribute(Const.CURRENT_USER);
        if (teacher==null){
            return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"用户未登录请先登录");
        }else {

            return iWorktrendService.searchWorktred(title,soureCrmpy,wtId,pageNum,pageSize);
        }
    }

    /**
     * 后台工作状态是否置顶
     * @param session
     * @param wtId
     * @return
     */
    @RequestMapping(value = "state.do",method = RequestMethod.POST)
    @ResponseBody
    public  ServerResponse state (HttpSession session, @RequestParam(value = "wtId") Integer wtId){

        Teacher teacher= (Teacher) session.getAttribute(Const.CURRENT_USER);
        if (teacher==null){
            return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"用户未登录请先登录");
        }else {
            return iWorktrendService.selectOrState(wtId);
        }
    }














}
